package com.cloud.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 2020/3/18
 * RibbonClientService
 *
 * @author machuanpeng
 */
@Service
public class RibbonClientService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "homeRibbonServiceErr")
    public String homeRibbonService(String name) {
        return restTemplate.getForObject("http://eureka-client-demo/eureka/client/home?name=" + name, String.class);
    }

    /**
     * homeRibbonService功能的熔断方法.
     * 2020/3/18
     *
     * @param name name
     * @return java.lang.String
     * @author machuanpeng
     */
    private String homeRibbonServiceErr(String name) {
        return "hi," + name + ",sorry,error!";
    }

}
